package chapter4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GoBang {
    private static int BROAD_SIZE = 15;
    private String broad[][];

    public void initBroad() {
        broad = new String[BROAD_SIZE][BROAD_SIZE];
        for (int i = 0; i < BROAD_SIZE; i++) {
            for (int j = 0; j < BROAD_SIZE; j++) {
                broad[i][j] = "✚";
            }
        }
    }

    public void printBroad() {
        for (int i = 0; i < BROAD_SIZE; i++) {
            for (int j = 0; j < BROAD_SIZE; j++) {
                System.out.print(broad[i][j]);
            }
            System.out.print("\n");
        }
    }

    public static void main(String[] args) throws IOException {
        GoBang goBang = new GoBang();
        goBang.initBroad();
        goBang.printBroad();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String position;
        while ((position = br.readLine()) != null) {
            String[] pos = position.split(",");
            Integer xpos = Integer.parseInt(pos[0]);
            Integer ypos = Integer.parseInt(pos[1]);
            goBang.broad[xpos - 1][ypos - 1] = "●";
            //生成两个随机数，模拟自动下棋
            Integer autoPosX = (int) (Math.random() * BROAD_SIZE);
            Integer autoPosY = (int) (Math.random() * BROAD_SIZE);
            System.out.println("生成的x和y坐标为:" + autoPosX + "," + autoPosY);
            goBang.broad[autoPosX - 1][autoPosY - 1] = "✖";
            goBang.printBroad();
            System.out.println("请输入您下棋的坐标,应该以x,y的格式: ");
        }
    }
}
